﻿namespace NTLib.Core.Pool
{
    using System;

    /// <summary>
    /// Defines method to recycling the object in the pool.
    /// </summary>
    public interface IPoolItem : IDisposable
    {
        #region Event

        /// <summary>
        /// Occurs when the item disposed.
        /// </summary>
        event Action<object> ItemDisposed; 
        
        #endregion

        #region Methods

        /// <summary>
        /// Resets this instance.
        /// Everything MUST be initialized on this method.
        /// This method must be called only by the pool manager to initialize or reset the object.
        /// </summary>
        /// <permission cref="IPool">This Method must be called only by the pool manager.</permission>
        /// <remarks>In this method you must clear all the data of your object.</remarks>
        /// <param name="poolInstance">Instance of the pool where the object is attach.</param>
        void Reset(IPool poolInstance);

        /// <summary>
        /// Destroys this instance.
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// This method must be called only by the pool managed when the instance is no more needed.
        /// </summary>
        /// <permission cref="IPool">This Method must be called only by the pool manager.</permission>
        /// <remarks>This methods is used to free all the memory used by the object.</remarks>
        void Destroy();

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// After the call of this method the object would be reinjected in the (<see cref="IPool"/>) owner's pool to be reuse.
        /// </summary>
        new void Dispose();

        #endregion
    }
}
